package primenumbers;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.Semaphore;

public class ParallelFactor {
	private static final BigInteger TWO = new BigInteger("2");
	private static Semaphore isEmpty = new Semaphore(0);
	private static Semaphore outro = new Semaphore(0);	
	private static Queue<BigInteger> primes = new LinkedList<BigInteger>();

	public static void main(String[] args) {
		ArrayList<BigInteger> factors = new ArrayList<BigInteger>();
		
		BigInteger N = new BigInteger("1000578901234567890");
		//BigInteger N = new BigInteger("9223372036854775807");
		//BigInteger N = new BigInteger("2147483647");
		//BigInteger N = new BigInteger("21");
		BigInteger root = new BigInteger("");
		
		for (BigInteger d = TWO; d.compareTo(root) < 0; d = d.add(BigInteger.ONE)) {
			BigInteger x[] = N.divideAndRemainder(d);

			while (x[1].equals(BigInteger.ZERO)) {
				factors.add(d);
				N = x[0];
				x = N.divideAndRemainder(d);
				System.out.println(d);
			}

			if (N.equals(BigInteger.ONE)) {
				break;
			}
		}

		if (N.compareTo(BigInteger.ONE) > 0) {
			factors.add(N);
		}
	}
}